var nav_vm = new Vue({
	el:'.navbar',
	data:{
		activeIndex:activeIndex,
		user:null
	},
	computed:{
		token(){
			return localStorage.token || Cookies.get('token')
		},
		hasPermission(){
			if(this.user){
				var administrators = ['admin','director']
				// var staff = ['deputy_director','principal','main_principal','staff']
				return _.indexOf(administrators,this.user.roles[0].name)!==-1
			}
		},
		no_score(){
			return this.user.roles[0].name == 'admin'
		}
	},
	methods:{
		getUserInfo(){
			var self = this
			axios.get(window.config.host + '/user_info',{
				headers:{
					Authorization: 'Bearer '+ this.token
				}
			})
			.then(function(res){
				if(res.status == 200){
					self.user = res.data.data
					localStorage.userinfo = JSON.stringify(res.data.data)
					Cookies.set('userinfo',JSON.stringify(res.data.data))
				}else{
					console.log(res.data.message)
				}
			})
		},
		logout(){
			localStorage.userinfo = null
			localStorage.token = null
			Cookies.set('userinfo',null)
			Cookies.set('token',null)
			window.location.href = '/'
		},
		//开启考核
		createYear(){
			axios.get(window.config.host+'/create_year',{
				headers:{
					Authorization: 'Bearer '+ this.token
				}
			}).then(function (res) {
				if(res.status==200){
					alert('开启成功')
				}else {
					alert('开启失败')
				}
			})
		},
		//评分结算
		createScore(){
			axios.get(window.config.host+'/create_score',{
				headers:{
					Authorization: 'Bearer '+ this.token
				}
			}).then(function (res) {
				if(res.status==200){
					alert('结算成功')
				}else {
					alert('结算失败')
				}
			})
		}
	},
	created(){
		try{
			var userinfo = localStorage.userinfo || Cookies.get('userinfo')
			this.user = JSON.parse(userinfo)
            this.getUserInfo()
		}
		catch(err){
			this.getUserInfo()
		}
	}
})